package cn.xuan.scan.common.utils;

import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class XMLFileReader {
	private Document document = null;

	public List getSelectElements(String path) {
		return this.document.selectNodes(path);
	}

	public List getSelectElements(Element element, String path) {
		return element.selectNodes(path);
	}

	public XMLFileReader(String fileName) {
		ClassLoader cl = this.getClass().getClassLoader();
		InputStream input = cl.getResourceAsStream(fileName);
		SAXReader reader = new SAXReader();

		try {
			this.document = reader.read(input);
		} catch (Exception var6) {
			var6.printStackTrace();
		}

	}

	public String getPorpertyText(String porpertyPath) {
		Node node = this.document.selectSingleNode(porpertyPath);
		return node.getText();
	}

	public String getPorpertyTexts(String porpertyPath, String nodeName, String divisionChar) {
		StringBuffer cp = new StringBuffer("");
		List list = this.document.selectNodes(porpertyPath + "/" + nodeName);
		Iterator it = list.iterator();

		while (it.hasNext()) {
			Node node = (Node) it.next();
			cp.append(node.getText() + divisionChar);
		}

		if (cp.length() > 1) {
			cp.deleteCharAt(cp.length() - 1);
		}

		return cp.toString();
	}

	public Vector getPorpertyTexts(String porpertyPath, String nodeName) {
		Vector vReturn = new Vector();
		List list = this.document.selectNodes(porpertyPath + "/" + nodeName);
		Iterator it = list.iterator();

		while (it.hasNext()) {
			Node node = (Node) it.next();
			node.getName();
			node.getText();
		}

		return vReturn;
	}

	public Document getDocument() {
		return document;
	}

	public void setDocument(Document document) {
		this.document = document;
	}
}
